package cn.hcbycloud.stream.service;



import cn.hcbycloud.stream.dto.StreamMessageDTO;
import cn.hcbycloud.stream.service.channel.DefaultOutputChannelProcessor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

/**
 * @author gaoh
 * @desc
 * @date 2022年02月11日 下午 10:25
 */
@Slf4j
@EnableBinding(value ={DefaultOutputChannelProcessor.class})
public class SendMessageProducer {
    @Autowired
    @Output(DefaultOutputChannelProcessor.DEFAULT_OUTPUT)
    private MessageChannel channel;

    /**
     * 发送消息
     * @param message
     */
    public void sendMsg(StreamMessageDTO message) {
        channel.send(MessageBuilder.withPayload(message).build());
        log.info("消息发送成功：" + message.toString());
    }
}
